import crypto from 'crypto'

/**
 * @param {*} value 将要加密的值
 */
function md5Hex(value){
    return crypto.createHash('md5').update(value,'UTF-8').digest('hex')
}

export const md5Hex

/**
 * @param {*} data 将要加密的内容
 * @param {*} key 加密使用的key
 */
function aesEncrypt(data,key){
    const cipher = crypto.createCipher('aes192',key)
    let crypted = cipher.update(data, 'utf8', 'hex');
    crypted += cipher.final('hex');
    return crypted;
}

export const aesEncrypt

/**
 * @param {*} encrypted 将要解密的字符串
 * @param {*} key 解密使用的key
 */
function aesDecrypt(encrypted, key) {
    const decipher = crypto.createDecipher('aes192', key);
    let decrypted = decipher.update(encrypted, 'hex', 'utf8');
    decrypted += decipher.final('utf8');
    return decrypted;
}

export const aesDecrypt